package nix.anim.cms.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import nix.anim.cms.service.CmsCateService;
import nix.anim.common.pojo.LogAnnotation;
import nix.anim.common.pojo.NixResult;
import nix.anim.pojo.CmsCategory;

/**
 * 栏目管理Controller
 */
@Controller
public class CmsCateController {

	@Autowired
	private CmsCateService cmsCateService;
	
	@Value("${ROOT_CMS_CATE_ID}")
	private Integer ROOT_CMS_CATE_ID;
	
	@RequestMapping(value="/api/cms/cate/tree", method=RequestMethod.POST)
	@ResponseBody
	public NixResult getCmsCateTree(Integer siteId) {
		// 调用服务
		NixResult result = cmsCateService.getCmsCateTree(ROOT_CMS_CATE_ID, siteId);
		return result;
	}
	
	@RequestMapping(value="/api/cms/cate/list", method=RequestMethod.GET)
	@ResponseBody
	public NixResult getListWithTreeOrder(Integer siteId) {	
		// 调用服务
		NixResult result = cmsCateService.getListWithTreeOrder(siteId);
		return result;
	}
	
	@RequestMapping(value="/api/cms/cate/save", method=RequestMethod.POST)
	@ResponseBody
	@LogAnnotation(action="新增/修改", object="栏目")
	public NixResult saveCmsCate(CmsCategory cmsCate) {
		NixResult result = new NixResult();
		if (cmsCate.getId() == null) {
			// Add
			result = cmsCateService.addCmsCate(cmsCate);
		} else {
			// Update
			result = cmsCateService.updateCmsCate(cmsCate);
		}
		return result;
	}
}
